home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / KJVQPU (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  6.6 KB  |  249 lines

  1. package com.sun.java.swing;
  2.  
  3. import com.sun.java.accessibility.Accessible;
  4. import com.sun.java.accessibility.AccessibleContext;
  5. import com.sun.java.swing.plaf.LabelUI;
  6. import java.awt.Component;
  7. import java.awt.Container;
  8. import java.awt.Font;
  9. import java.awt.Image;
  10.  
  11. public class JLabel extends JComponent implements SwingConstants, Accessible {
  12.    private int mnemonic;
  13.    private String text;
  14.    private Icon defaultIcon;
  15.    private Icon disabledIcon;
  16.    private int verticalAlignment;
  17.    private int horizontalAlignment;
  18.    private int verticalTextPosition;
  19.    private int horizontalTextPosition;
  20.    private int iconTextGap;
  21.    protected Component labelFor;
  22.  
  23.    public JLabel() {
  24.       this("", (Icon)null, 2);
  25.    }
  26.  
  27.    public JLabel(Icon image) {
  28.       this((String)null, image, 0);
  29.    }
  30.  
  31.    public JLabel(Icon image, int horizontalAlignment) {
  32.       this((String)null, image, horizontalAlignment);
  33.    }
  34.  
  35.    public JLabel(String text) {
  36.       this(text, (Icon)null, 2);
  37.    }
  38.  
  39.    public JLabel(String text, int horizontalAlignment) {
  40.       this(text, (Icon)null, horizontalAlignment);
  41.    }
  42.  
  43.    public JLabel(String text, Icon icon, int horizontalAlignment) {
  44.       this.mnemonic = 0;
  45.       this.text = "";
  46.       this.defaultIcon = null;
  47.       this.disabledIcon = null;
  48.       this.verticalAlignment = 0;
  49.       this.horizontalAlignment = 2;
  50.       this.verticalTextPosition = 0;
  51.       this.horizontalTextPosition = 4;
  52.       this.iconTextGap = 4;
  53.       this.labelFor = null;
  54.       this.setText(text);
  55.       this.setIcon(icon);
  56.       this.setHorizontalAlignment(horizontalAlignment);
  57.       this.updateUI();
  58.       ((JComponent)this).setAlignmentX(0.0F);
  59.    }
  60.  
  61.    protected int checkHorizontalKey(int key, String message) {
  62.       if (key != 2 && key != 0 && key != 4) {
  63.          throw new IllegalArgumentException(message);
  64.       } else {
  65.          return key;
  66.       }
  67.    }
  68.  
  69.    protected int checkVerticalKey(int key, String message) {
  70.       if (key != 1 && key != 0 && key != 3) {
  71.          throw new IllegalArgumentException(message);
  72.       } else {
  73.          return key;
  74.       }
  75.    }
  76.  
  77.    public AccessibleContext getAccessibleContext() {
  78.       if (super.accessibleContext == null) {
  79.          super.accessibleContext = new AccessibleJLabel(this);
  80.       }
  81.  
  82.       return super.accessibleContext;
  83.    }
  84.  
  85.    public Icon getDisabledIcon() {
  86.       if (this.disabledIcon == null && this.defaultIcon != null && this.defaultIcon instanceof ImageIcon) {
  87.          Image grayImage = GrayFilter.createDisabledImage(((ImageIcon)this.defaultIcon).getImage());
  88.          this.disabledIcon = new ImageIcon(grayImage);
  89.          ((JComponent)this).firePropertyChange("disabledIcon", (Object)null, this.disabledIcon);
  90.       }
  91.  
  92.       return this.disabledIcon;
  93.    }
  94.  
  95.    public int getDisplayedMnemonic() {
  96.       return this.mnemonic;
  97.    }
  98.  
  99.    public int getHorizontalAlignment() {
  100.       return this.horizontalAlignment;
  101.    }
  102.  
  103.    public int getHorizontalTextPosition() {
  104.       return this.horizontalTextPosition;
  105.    }
  106.  
  107.    public Icon getIcon() {
  108.       return this.defaultIcon;
  109.    }
  110.  
  111.    public int getIconTextGap() {
  112.       return this.iconTextGap;
  113.    }
  114.  
  115.    public Component getLabelFor() {
  116.       return this.labelFor;
  117.    }
  118.  
  119.    public String getText() {
  120.       return this.text;
  121.    }
  122.  
  123.    public LabelUI getUI() {
  124.       return (LabelUI)super.ui;
  125.    }
  126.  
  127.    public String getUIClassID() {
  128.       return "LabelUI";
  129.    }
  130.  
  131.    public int getVerticalAlignment() {
  132.       return this.verticalAlignment;
  133.    }
  134.  
  135.    public int getVerticalTextPosition() {
  136.       return this.verticalTextPosition;
  137.    }
  138.  
  139.    public void setDisabledIcon(Icon disabledIcon) {
  140.       Icon oldValue = this.disabledIcon;
  141.       this.disabledIcon = disabledIcon;
  142.       ((JComponent)this).firePropertyChange("disabledIcon", oldValue, disabledIcon);
  143.       ((Component)this).repaint(10L);
  144.    }
  145.  
  146.    public void setDisplayedMnemonic(char aChar) {
  147.       int vk = aChar;
  148.       if (aChar >= 'a' && aChar <= 'z') {
  149.          vk = aChar - 32;
  150.       }
  151.  
  152.       this.setDisplayedMnemonic(vk);
  153.    }
  154.  
  155.    public void setDisplayedMnemonic(int key) {
  156.       int oldKey = this.mnemonic;
  157.       this.mnemonic = key;
  158.       ((JComponent)this).firePropertyChange("displayedMnemonic", oldKey, this.mnemonic);
  159.       ((Component)this).repaint();
  160.    }
  161.  
  162.    public void setFont(Font font) {
  163.       super.setFont(font);
  164.       ((Component)this).repaint(10L);
  165.    }
  166.  
  167.    public void setHorizontalAlignment(int alignment) {
  168.       if (alignment != this.horizontalAlignment) {
  169.          int oldValue = this.horizontalAlignment;
  170.          this.horizontalAlignment = this.checkHorizontalKey(alignment, "horizontalAlignment");
  171.          ((JComponent)this).firePropertyChange("horizontalAlignment", oldValue, this.horizontalAlignment);
  172.          ((Component)this).repaint(10L);
  173.       }
  174.    }
  175.  
  176.    public void setHorizontalTextPosition(int x) {
  177.       if (x != this.horizontalTextPosition) {
  178.          this.horizontalTextPosition = this.checkHorizontalKey(x, "horizontalTextPosition");
  179.          ((Component)this).repaint(10L);
  180.       }
  181.    }
  182.  
  183.    public void setIcon(Icon icon) {
  184.       this.defaultIcon = icon;
  185.       ((JComponent)this).firePropertyChange("icon", icon, this.defaultIcon);
  186.       if (super.accessibleContext != null && icon != this.defaultIcon) {
  187.          super.accessibleContext.firePropertyChange("AccessibleVisibleData", icon, this.defaultIcon);
  188.       }
  189.  
  190.       ((Component)this).repaint(10L);
  191.    }
  192.  
  193.    public void setIconTextGap(int iconTextGap) {
  194.       this.iconTextGap = iconTextGap;
  195.       ((JComponent)this).firePropertyChange("iconTextGap", iconTextGap, iconTextGap);
  196.       ((Container)this).invalidate();
  197.       ((Component)this).repaint(10L);
  198.    }
  199.  
  200.    public void setLabelFor(Component c) {
  201.       Component oldC = this.labelFor;
  202.       this.labelFor = c;
  203.       ((JComponent)this).firePropertyChange("labelFor", oldC, c);
  204.    }
  205.  
  206.    public void setText(String text) {
  207.       String oldAccessibleName = null;
  208.       if (super.accessibleContext != null) {
  209.          oldAccessibleName = super.accessibleContext.getAccessibleName();
  210.       }
  211.  
  212.       String oldValue = this.text;
  213.       this.text = text;
  214.       ((JComponent)this).firePropertyChange("text", oldValue, text);
  215.       if (super.accessibleContext != null && super.accessibleContext.getAccessibleName() != oldAccessibleName) {
  216.          super.accessibleContext.firePropertyChange("AccessibleVisibleData", oldAccessibleName, super.accessibleContext.getAccessibleName());
  217.       }
  218.  
  219.       ((Component)this).repaint();
  220.    }
  221.  
  222.    public void setUI(LabelUI ui) {
  223.       super.setUI(ui);
  224.    }
  225.  
  226.    public void setVerticalAlignment(int alignment) {
  227.       if (alignment != this.verticalAlignment) {
  228.          int oldValue = this.verticalAlignment;
  229.          this.verticalAlignment = this.checkVerticalKey(alignment, "verticalAlignment");
  230.          ((JComponent)this).firePropertyChange("verticalAlignment", oldValue, this.verticalAlignment);
  231.          ((Component)this).repaint(10L);
  232.       }
  233.    }
  234.  
  235.    public void setVerticalTextPosition(int textPosition) {
  236.       if (textPosition != this.verticalTextPosition) {
  237.          int oldValue = this.verticalTextPosition;
  238.          this.verticalTextPosition = this.checkVerticalKey(textPosition, "verticalTextPosition");
  239.          ((JComponent)this).firePropertyChange("verticalTextPosition", oldValue, this.verticalTextPosition);
  240.          ((Component)this).repaint(10L);
  241.       }
  242.    }
  243.  
  244.    public void updateUI() {
  245.       this.setUI((LabelUI)UIManager.getUI(this));
  246.       ((Container)this).invalidate();
  247.    }
  248. }
  249.